// pages/appointment/clientment/clientment.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: false,//上拉变量
        loadingconflg: false, //没有数据时变量
        nodata: false,//是否有数据
        listdata: [],
        page: 1,//页码
        totalpage:1,//总页数
        cid: 0,
        visituser: {}//访问的用户信息
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        this.setData({
            "cid": options.cid
        })
        this.GetVisitUser();
        this.GetList();
    },

    GetVisitUser: function () {
        var cid = this.data.cid;
        app.http.POST("/MiniCardUser/GetVisitUserInfo", { "cid": cid }, (err, data) => {
            if (data.code == 1) {
                this.setData({
                    "visituser": data.data
                })
                wx.hideLoading()
            } else {
                wx.showToast({
                    title: '访问用户信息获取失败',
                    icon: 'none',
                    duration: 2000
                })
            }
        })
    },

    GetList: function () {
        wx.showLoading({
            title: '加载中',
        })
        var cid = this.data.cid;
        var page = this.data.page;
        var _this=this;
        var listdata = _this.data.listdata;
        app.http.POST("/MiniCardProject/GetPageProject", { "cid": cid, "page": page}, (err, data) => {
            if (data.code == 1) {
                if (data.data.List == null || data.data.List.length < 1){
                    _this.setData({
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": true
                    })
                }else{
                    listdata = listdata.concat(data.data.List);
                    _this.setData({
                        "listdata": listdata,
                        "totalpage": data.data.TotalPage,
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": false
                    })
                }
            } else {
                wx.showToast({
                    title: '获取列表失败',
                    icon: 'none',
                    duration: 2000
                })
                _this.setData({
                    "loading": false,
                    "nodata": true
                })
            }
            wx.hideLoading();
        })
    },
    //滚动加载
    lower: function (e) {
        var _this = this;
        var page = _this.data.page + 1;
        if (page <= _this.data.totalpage) {
            _this.setData({
                "page": page,
                "loading": true,
                "loadingconflg": true,
            })
            _this.GetList();
        } else {
            _this.setData({
                "loading": true,
                "loadingconflg": false,
            })
        }
    },
    //预约按钮点击事件
    Reserva:function(e){
        console.log(e);
        var projectId=e.currentTarget.dataset.id;
        var projectName = e.currentTarget.dataset.name;
        var cid=this.data.cid;
        console.log(projectId);
        wx.navigateTo({
            url: 'menttimes?cid=' + cid + '&pid=' + projectId + '&pname=' + projectName + '&vname=' + this.data.visituser.NickName,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: this.data.visituser.NickName + "的美名片",
            path: "/pages/index/index?cid=" + this.data.cid,
            success: function (res) {
                wx.showToast({
                    title: '分享成功',
                    icon: "success",
                    duration: 200
                })
            }
        }
    }
})